package com.yanfan.energybilling.controller;

import com.yanfan.common.annotation.Anonymous;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.utils.StringUtils;
import com.yanfan.energybilling.domain.vo.StaticRequestParamVo;
import com.yanfan.energybilling.service.IEnergyStatisticsService;
import com.yanfan.iot.model.DeviceHistoryParam;
import io.swagger.annotations.ApiOperation;
import org.mapstruct.Qualifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/energy/statistics")
public class EnergyStatisticsController extends BaseController {

    @Autowired
    private IEnergyStatisticsService energyStatisticsService;

    @GetMapping("/buildingEnergy")
    public AjaxResult buildingEnergyStatistics() {
        energyStatisticsService.buildingEnergyStatistics();
        return success();
    }

    @GetMapping("/energyCost")
    public AjaxResult buildingEnergyStatistics(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyCost(param));
    }

    @GetMapping("/energyCostStatisticsTimeWindow")
    public AjaxResult energyCostStatisticsTimeWindow(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyCostStatisticsTimeWindow(param));
    }

    @GetMapping("/energyConsumeStatisticsTimeWindow")
    public AjaxResult energyConsumeStatisticsTimeWindow(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyConsumeStatisticsTimeWindow(param));
    }

    @GetMapping("/energyCountAllStatisticsTimeWindow")
    public AjaxResult energyCountAllStatisticsTimeWindow(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyCountAllStatisticsTimeWindow(param));
    }
    @GetMapping("/energyCountAllStatisticsTimeWindowPage")
    public TableDataInfo energyCountAllStatisticsTimeWindowPage(StaticRequestParamVo param) {
        startPage();
        return getDataTable(energyStatisticsService.energyCountAllStatisticsTimeWindow(param));
    }

    @GetMapping("/energyCostStatisticsTimeWindows")
    public AjaxResult energyCostStatisticsTimeWindows(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyCostStatisticsTimeWindows(param));
    }

    @GetMapping("/energyCostStatisticsTimeWindowsByType")
    public AjaxResult energyCostStatisticsTimeWindowsByType(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyCostStatisticsTimeWindowsByType(param));
    }

    @ApiOperation("综合水/气费")
    @GetMapping("/energyCostStatisticsTimeWindowsByWater")
    public AjaxResult energyCostStatisticsTimeWindowsByWater(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyCostStatisticsTimeWindowsByWater(param));
    }

    @ApiOperation("综合水/气费图表")
    @Anonymous
    @GetMapping("/energyCostStatisticsTimeWindowsByDate")
    public TableDataInfo energyCostStatisticsTimeWindowsByDate(StaticRequestParamVo param) {
        startPage();
        return getDataTable(energyStatisticsService.energyCostStatisticsTimeWindowsByDate(param));
    }

    @GetMapping("/energyCostStatisticsTimeWindowsByBuilding")
    public AjaxResult energyCostStatisticsTimeWindowsByBuilding(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyCostStatisticsTimeWindowsByBuilding(param));
    }

    @GetMapping("/buildingEnergyFlowStatistics")
    public AjaxResult buildingEnergyFlowStatistics(StaticRequestParamVo param) {
        return success(energyStatisticsService.buildingEnergyFlowStatistics(param));
    }

    @GetMapping("/energyComparisonOfTheSameCycle")
    public AjaxResult energyComparisonOfTheSameCycle(StaticRequestParamVo param) {
        return success(energyStatisticsService.energyComparisonOfTheSameCycle(param));
    }

    @ApiOperation("导出设备的历史能源数据")
    @PostMapping("/exportEnergyDeviceHistory")
    public void exportEnergyDeviceHistory(HttpServletResponse response, @RequestBody StaticRequestParamVo param) {
            energyStatisticsService.exportEnergyDeviceHistory(response,param);
    }
}
